package com.jinbo.footmessage.baiduMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.jinbo.footmessage.R;
import com.jinbo.footmessage.utils.HighLightTextUtil;

import java.util.ArrayList;

public class SelectAddressSearchAdapter extends BaseAdapter {
		private Context context; //�����Ķ�������
		//private int cur_pos=-1; //�б�λ��
		ArrayList<String> address_name;
		ArrayList<String> address_detail;
	    private String mKeyWord;
		public SelectAddressSearchAdapter(Context context, ArrayList<String> address_name, ArrayList<String> address_detail, String keyWord)//,int currentPos)
		{
			this.context = context;
			this.address_name=address_name;
			this.address_detail=address_detail;
			this.mKeyWord=keyWord;
		}

		
		@Override
		public int getCount()
		{
			return address_name.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}
		
		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			convertView= LayoutInflater.from(context).inflate(R.layout.list_selectaddress_item,null);
			TextView tvName=(TextView)convertView.findViewById(R.id.address_name);
			TextView tvDetail=(TextView)convertView.findViewById(R.id.address_detail);
			String name=address_name.get(position);
			String detail=address_detail.get(position);



			if(name!=null){
				if(mKeyWord!=null)
				  tvName.setText(HighLightTextUtil.highlightText(context, name, mKeyWord));
				else
					tvName.setText(name);
			}
			if(detail !=null){
				if(mKeyWord!=null)
				   tvDetail.setText(HighLightTextUtil.highlightText(context, detail, mKeyWord));
				else
					tvDetail.setText(detail);
			}

			return convertView;
		}
}
